----------------------------------Spell Variables--------------------------------------
SPELL.m_iSpellID = 11410 -- Whatever value you want as long as it doesn't override any other spells' IDs.
SPELL.m_iRange = 1024
SPELL.m_sName = "Fireball"
SPELL.m_sToolTip =	[[You cast a fireball at the
					target, dealing 25 damage and
					causing 15 damage over 3 seconds.]]
SPELL.m_sIcon = "devin/blackbetty/spells/mage/fireball.png"
SPELL.m_iCoolDown = 2
SPELL.m_iManaCost = 0
SPELL.m_bRequiresTarget = true
SPELL.m_iSpellType = SPELLTYPE_RANGEDAMAGE
SPELL.m_sUsedBy = "class_ranger"

---------------------------------------------------------------------------------------

function SPELL:Cast( pl, target )
	
	print("Casted "..self.m_sName.."!")
	
	local range = self.m_iRange
	local casttime = 2
	
	ParticleEffectAttach( "fire_hands", PATTACH_POINT_FOLLOW, pl, pl:LookupAttachment("anim_attachment_RH"))
	
	local castingloop = "devin/blackbetty/weapons/castingloops/Fire.wav"
	
	self.CastSound = CreateSound( pl, castingloop )
	self.CastSound:Play()
	pl.DoingCast = true
	pl.CastWhileMoving = true
	net.Start( "SendPlayerCast" )
	local SendTable = {casttime, self.m_sName, Color(155, 15, 15, 155)}
	net.WriteTable(SendTable)
	net.Send(pl)
	
	timer.Simple(casttime, function()
		pl:SetNWBool("Casting", false)
		pl:SetNWBool("Casted", false)
		pl.DoingCast = false
		pl.CastWhileMoving = false
		self.CastSound:Stop()
		if(target && target:IsValid() && target != pl) then
			if(pl:GetPos():Distance(target:GetPos()) < range)then
				pl:StopParticles()
				ParticleEffectAttach( "fire_glow", PATTACH_POINT_FOLLOW, pl, pl:LookupAttachment("anim_attachment_RH"))
				self:Effect(pl, target)
				--self:ApplySpellMods(self, pl, target)
			end
		end
	end)
end

function SPELL:Effect(pl, target)

	pl:SetNWString("HoldType", "normal")
	local weapon = pl:GetWeapon("weapon_all")
	
	pl:DoAnimationEvent(ACT_HL2MP_GESTURE_RANGE_ATTACK_KNIFE)
	pl:EmitSound("devin/blackbetty/weapons/castsounds/FireCast.wav", 150, 130+math.random(10,20))
	if(SERVER)then
		local myhitdelay = ((pl:GetPos() - target:GetPos()):Length()/2200)
		LaunchProjectile(pl, target, 0, "pummel_hit", "", "fire_hands", "devin/blackbetty/weapons/travelsounds/FireMissileLoop.wav", myhitdelay, 2400, "models/crossbow_bolt.mdl")
		timer.Simple(myhitdelay, function()
			self:DealDamage(weapon.MinWeaponDamage*2, weapon.MaxWeaponDamage*2, pl, target, DMG_BURN)
			pl:EmitSound("devin/blackbetty/weapons/hit/Fire1.wav", 150, 80+math.random(10,20))
			ParticleEffect( "burning", target:GetPos() + Vector(0, 0, 45), Angle(0,0,0), target )
			ParticleEffect( "impact_firebig", target:GetPos() + Vector(0, 0, 32), Angle(0,0,0), pl )
			ParticleEffect( "pummel_hit", target:GetPos() + Vector(0, 0, 45), Angle(0,0,0), target )
			AddEffect(target, 4, ""..pl:GetName().."Burned", {pl, DMG_BURN}, 5, 3, 1)
		end)
	end
end




